import Layout from '@/views/layout/Layout';

// 控制这系列页面的权限
const authData = {
  dayAccount: ['crm:finance:read', 'crm:finance:adminShow', 'crm:finance:departAll'], // 财务流水
  sealingAccount: [
    'crm:finance:sealAccountRead', 'crm:finance:submitSealAmount', 'crm:finance:sellFirstTrial', 'crm:finance:financeRecheck', 'crm:finance:financeReport'
  ], // 财务封账
  issueInvoice: ['invoice:issue:read'], // 开票申请
  invoice: ['crm:receipt:read'], // 发票管理
  costManageList: ['crm:cost:read'], // 成本管理
  invoiceAbandon: ['invoice:abandon:read'],
  supplier: ['medium:supplierAudit:read'], // 付款申请
  reimbursement: ['crm:reimbursement:read'], // 员工报销
  loan: ['crm:loan:read'], // 借款申请
  payBack: ['crm:payBack:read'], // 还款申请
  inputInvoice: ['crm:inputInvoice:read'], // 进项发票
  arrearsTransfer: ['crm:arrearsTransfer:read'], // 转交欠款
  intelligentList: ['crm:finance:autoWriteOff'] // 转交欠款
};
let pageAllAuth = [];
for (const key in authData) {
  pageAllAuth = pageAllAuth.concat(authData[key]);
}
// 列表页放这里
const listRouter = [
  // 以下页面在侧边栏中会展示在 "核算" tab之下
  {
    path: 'dayAccount',
    parentName: '核算',
    component: () => import('@/views/finance/dayAccount/index'),
    name: 'dayAccount',
    meta: {
      title: '财务流水',
      authControl: authData.dayAccount,
      keepAlive: true,
      isChange: true,
      headerBarShow: true,
      headerParams: [
        { pathName: 'dayAccount', title: '财务流水', active: true },
        { pathName: 'chargeReport', title: '核销记录', auth: 'crm:chargeReport:read' }
      ]
    }
  }, {
    path: 'intelligentList',
    name: 'intelligentList',
    hidden: true,
    component: () => import('@/views/finance/dayAccount/intelligentList'),
    meta: { title: '智能核销列表', authControl: authData.intelligentList, keepAlive: true, isChange: true, headerBarShow: true, activeMenu: '/businessPage/dayAccount' }
  }, {
    path: 'sealingAccount',
    parentName: '核算',
    component: () => import('@/views/finance/sealingAccount/index'),
    name: 'sealingAccount',
    meta: { title: '财务封账', authControl: authData.sealingAccount, headerBarShow: false }
  }, {
    path: 'costManageList',
    parentName: '核算',
    name: 'costManageList',
    component: () => import('@/views/cost/index'),
    meta: {
      title: '成本管理', keepAlive: true, isChange: true, headerBarShow: false, authControl: authData.costManageList }
  }, {
    path: 'chargeReport',
    parentName: '核算',
    component: () => import('@/views/finance/chargeReport/index'),
    name: 'chargeReport',
    meta: {
      activeMenu: '/businessPage/dayAccount',
      title: '核销记录',
      authControl: authData.dayAccount,
      keepAlive: false,
      isChange: true,
      headerBarShow: true,
      headerParams: [
        { pathName: 'dayAccount', title: '财务流水' },
        { pathName: 'chargeReport', title: '核销记录', active: true, auth: 'crm:chargeReport:read' }
      ]
    },
    hidden: true
  },
  // 以下页面在侧边栏中会展示在 "发票" tab之下
  {
    path: 'issueInvoice',
    name: 'issueInvoice',
    parentName: '发票',
    component: () => import('@/views/issueInvoice/index'),
    meta: { title: '开票申请', authControl: authData.issueInvoice, keepAlive: true, isChange: true, headerBarShow: false }
  }, {
    path: 'invoiceAbandon',
    name: 'invoiceAbandon',
    parentName: '发票',
    component: () => import('@/views/invoice/abandon/index'),
    meta: { title: '发票作废', authControl: authData.invoiceAbandon, keepAlive: true, isChange: true, headerBarShow: false }
  }, {
    path: 'invoice',
    name: 'invoice',
    parentName: '发票',
    component: () => import('@/views/invoice/index'),
    meta: { title: '销项发票', authControl: authData.invoice, keepAlive: true, isChange: true, headerBarShow: false }
  }, {
    path: 'inputInvoice',
    name: 'inputInvoice',
    parentName: '发票',
    component: () => import('@/views/inputInvoice/index'),
    meta: { title: '进项发票', authControl: authData.inputInvoice, keepAlive: true, isChange: true, headerBarShow: false }
  },
  // 以下页面在侧边栏中会展示在 "审批" tab之下
  {
    path: 'supplier',
    component: () => import('@/views/supplier/index'),
    name: 'supplier',
    parentName: '审批',
    meta: { title: '付款申请', authControl: authData.supplier, keepAlive: true, isChange: true, headerBarShow: false }
  },
  {
    path: 'reimbursement',
    name: 'reimbursement',
    parentName: '审批',
    component: () => import('@/views/reimbursement/index'),
    meta: { title: '员工报销', keepAlive: true, isChange: true, headerBarShow: false, authControl: authData.reimbursement }
  },
  {
    path: 'loan',
    name: 'loan',
    parentName: '审批',
    component: () => import('@/views/loan/index'),
    meta: { title: '借款申请', keepAlive: true, isChange: true, headerBarShow: false, authControl: authData.loan }
  }, {
    path: 'payBack',
    component: () => import('@/views/payBack/index'),
    name: 'payBack',
    parentName: '审批',
    meta: { title: '还款申请', authControl: authData.payBack, keepAlive: true, isChange: true, headerBarShow: false }
  }, {
    path: 'arrearsTransfer',
    name: 'arrearsTransfer',
    parentName: '审批',
    component: () => import('@/views/arrearsTransfer/index'),
    meta: { title: '转交欠款', authControl: authData.arrearsTransfer, keepAlive: true, isChange: true, headerBarShow: false }
  }
];
// 内页放这里
const inlineRouter = [
  {
    path: 'batchSettle',
    component: () => import('@/views/supplier/batchSettle'),
    name: 'batchSettle',
    hidden: true,
    meta: { title: '智能结算', headerBarShow: true, activeMenu: '/businessPage/supplier' }
  },
  // 财务流水
  {
    path: 'createDayAccount',
    component: () => import('@/views/finance/dayAccount/create/index'),
    name: 'createDayAccount',
    meta: { title: '新增流水单', keepAlive: false, headerBarShow: true, activeMenu: '/businessPage/dayAccount' },
    hidden: true
  },
  {
    path: 'editDayAccount/:dayAccountId',
    component: () => import('@/views/finance/dayAccount/create/index'),
    name: 'editDayAccount',
    meta: { title: '编辑流水单', keepAlive: false, headerBarShow: true, activeMenu: '/businessPage/dayAccount' },
    hidden: true
  },
  {
    path: 'chargeOff/:dayAccountId/:clientId',
    component: () => import('@/views/finance/chargeOff/index'),
    name: 'chargeOff',
    meta: { title: '核销页面', keepAlive: false, headerBarShow: true, activeMenu: '/businessPage/dayAccount' },
    hidden: true
  },
  {
    path: 'chargeOff/batchWriteOff',
    component: () => import('@/views/finance/batchWriteOff/index'),
    name: 'batchWriteOff',
    meta: { title: '核销页面', keepAlive: false, headerBarShow: true, activeMenu: '/businessPage/dayAccount' },
    hidden: true
  },
  {
    path: 'chargeOffDetail/:chargeOffId',
    component: () => import('@/views/finance/chargeOff/detail/index'),
    name: 'chargeOffDetail',
    meta: { title: '流水详情', keepAlive: false, headerBarShow: true, activeMenu: '/businessPage/dayAccount' },
    hidden: true
  },
  /** 财务封账 */
  {
    path: 'sealingStepsDetail/:id',
    component: () => import('@/views/finance/sealingAccount/sealingSteps/index'),
    name: 'sealingStepsDetail',
    meta: { title: '财务封账', keepAlive: false, isChange: false, headerBarShow: true, activeMenu: 'businessPage/sealingAccount' },
    hidden: true
  },
  {
    path: 'sealingAccountDetail/:sealingAccountId',
    component: () => import('@/views/finance/sealingAccount/detail/index'),
    name: 'sealingAccountDetail',
    meta: { title: '审批详情', keepAlive: false, headerBarShow: true, activeMenu: 'businessPage/sealingAccount' },
    hidden: true
  },
  /** 开票申请 */
  {
    path: 'issueInvoiceCreate',
    component: () => import('@/views/issueInvoice/create/index'),
    name: 'createIssueInvoice',
    meta: { title: '开票申请', headerBarShow: true, activeMenu: '/businessPage/issueInvoice' },
    hidden: true
  },
  {
    path: 'issueInvoiceEdit/:id',
    component: () => import('@/views/issueInvoice/create/index'),
    name: 'issueInvoiceEdit',
    meta: { title: '开票申请', headerBarShow: true, activeMenu: '/businessPage/issueInvoice' },
    hidden: true
  },
  {
    path: 'issueInvoiceDetail',
    component: () => import('@/views/issueInvoice/detail/index'),
    name: 'issueInvoiceDetail',
    meta: { title: '开票申请详情', headerBarShow: true, activeMenu: '/businessPage/issueInvoice' },
    hidden: true
  },
  // 发票管理内页
  {
    path: 'invoiceCreate',
    component: () => import('@/views/invoice/create/index'),
    name: 'createInvoice',
    meta: { title: '新增发票', headerBarShow: true, activeMenu: '/businessPage/invoice' },
    hidden: true
  },
  {
    path: 'invoiceEdit/:id',
    component: () => import('@/views/invoice/create/index'),
    name: 'editInvoice',
    meta: { title: '编辑发票', headerBarShow: true, activeMenu: '/businessPage/invoice' },
    hidden: true
  },
  {
    path: 'invoiceDetail/:id',
    component: () => import('@/views/invoice/detail/index'),
    name: 'invoiceDetail',
    meta: { title: '发票详情', headerBarShow: true, activeMenu: '/businessPage/invoice' },
    hidden: true
  },
  {
    path: 'invoiceAbandonCreate',
    component: () => import('@/views/invoice/abandon/create'),
    name: 'createInvoiceAbandon',
    meta: { title: '发票作废申请', headerBarShow: true, activeMenu: '/businessPage/invoiceAbandon' },
    hidden: true
  }, {
    path: 'invoiceAbandonEdit/:id',
    component: () => import('@/views/invoice/abandon/create'),
    name: 'editInvoiceAbandon',
    meta: { title: '发票作废申请', headerBarShow: true, activeMenu: '/businessPage/invoiceAbandon' },
    hidden: true
  },
  {
    path: 'invoiceAbandonDetail',
    component: () => import('@/views/invoice/abandon/detail'),
    name: 'invoiceAbandonDetail',
    meta: { title: '发票作废详情', headerBarShow: true, activeMenu: '/businessPage/invoiceAbandon' },
    hidden: true
  },
  // 进项发票
  {
    path: 'inputInvoiceDetail',
    component: () => import('@/views/inputInvoice/detail'),
    name: 'inputInvoiceDetail',
    meta: { title: '进项发票详情', headerBarShow: true, activeMenu: '/businessPage/inputInvoice' },
    hidden: true
  },
  {
    path: 'inputInvoiceAdd',
    component: () => import('@/views/inputInvoice/create'),
    name: 'inputInvoiceAdd',
    meta: { title: '进项发票', headerBarShow: true, activeMenu: '/businessPage/inputInvoice' },
    hidden: true
  },
  // 进项发票编辑页
  {
    path: 'inputInvoiceEdit',
    component: () => import('@/views/inputInvoice/create'),
    name: 'inputInvoiceEdit',
    meta: { title: '进项发票', headerBarShow: true, activeMenu: '/businessPage/inputInvoice' },
    hidden: true
  },
  // 成本管理-成本详情
  {
    path: 'costManageDetail/:id',
    name: 'costDetail',
    component: () => import('@/views/cost/detail'),
    hidden: true,
    meta: {
      title: '成本详情', headerBarShow: true, activeMenu: '/businessPage/costManageList' }
  },
  /* 付款申请内页 */
  {
    path: 'supplierCreate',
    name: 'supplierCreate',
    component: () => import('@/views/supplier/create'),
    meta: { title: '新建付款申请', diyTitle: '智能发起结算模式中...', isDiyTitle: false, activeMenu: '/businessPage/supplier', headerBarShow: true },
    hidden: true
  },
  {
    path: 'supplierEdit',
    name: 'supplierEdit',
    component: () => import('@/views/supplier/create'),
    meta: { title: '编辑付款申请', activeMenu: '/businessPage/supplier', headerBarShow: true },
    hidden: true
  },
  {
    path: 'supplierDetail',
    name: 'supplierDetail',
    component: () => import('@/views/supplier/detail'),
    meta: { title: '结算单详情', activeMenu: '/businessPage/supplier', headerBarShow: true },
    hidden: true
  },
  /* 借款申请内页 */
  {
    path: 'loancreate',
    component: () => import('@/views/loan/create'),
    name: 'createLoan',
    meta: { title: '借款申请', headerBarShow: true, activeMenu: '/businessPage/loan' },
    hidden: true
  },
  {
    path: 'loanEdit/:id',
    component: () => import('@/views/loan/create'),
    name: 'loanEdit',
    hidden: true,
    meta: { title: '借款申请', headerBarShow: true, activeMenu: '/businessPage/loan' }
  },
  {
    path: 'loanDetail',
    component: () => import('@/views/loan/detail'),
    name: 'loanDetail',
    meta: { title: '借款申请', headerBarShow: true, activeMenu: '/businessPage/loan' },
    hidden: true
  },
  /** 还款申请子页 */
  {
    path: 'payBackDetail',
    component: () => import('@/views/payBack/detail/index'),
    name: 'payBackDetail',
    meta: { title: '还款申请详情', headerBarShow: true, activeMenu: '/businessPage/payBack' },
    hidden: true
  },
  {
    path: 'payBackCreate',
    component: () => import('@/views/payBack/create/index'),
    name: 'payBackCreate',
    meta: { title: '还款申请', headerBarShow: true, activeMenu: '/businessPage/payBack' },
    hidden: true
  },
  {
    path: 'payBackEdit/:id',
    component: () => import('@/views/payBack/create/index'),
    name: 'payBackEdit',
    hidden: true,
    meta: { title: '还款申请', headerBarShow: true, activeMenu: '/businessPage/payBack' }
  },
  /* 转交欠款内页 */
  {
    path: 'arrearsTransferCreate',
    name: 'arrearsTransferCreate',
    component: () => import('@/views/arrearsTransfer/create'),
    meta: { title: '转交欠款', headerBarShow: true, activeMenu: '/businessPage/arrearsTransfer' },
    hidden: true
  },
  {
    path: 'arrearsTransferEdit/:id',
    name: 'arrearsTransferEdit',
    component: () => import('@/views/arrearsTransfer/create'),
    hidden: true,
    meta: { title: '转交欠款', headerBarShow: true, activeMenu: '/businessPage/arrearsTransfer' }
  },
  {
    path: 'arrearsTransferDetail',
    name: 'arrearsTransferDetail',
    component: () => import('@/views/arrearsTransfer/detail'),
    meta: { title: '转交欠款详情', headerBarShow: true, activeMenu: '/businessPage/arrearsTransfer' },
    hidden: true
  },
  /** 员工报销子页 */
  {
    path: 'reimbursementCreate',
    component: () => import('@/views/reimbursement/create/index'),
    name: 'createReimbursement',
    meta: { title: '员工报销', headerBarShow: true, activeMenu: '/businessPage/reimbursement' },
    hidden: true
  },
  {
    path: 'reimbursementEdit/:id',
    component: () => import('@/views/reimbursement/create/index'),
    name: 'reimbursementEdit',
    meta: { title: '员工报销', headerBarShow: true, activeMenu: '/businessPage/reimbursement' },
    hidden: true
  },
  {
    path: 'reimbursementDetail',
    component: () => import('@/views/reimbursement/detail/index'),
    name: 'reimbursementDetail',
    meta: { title: '员工报销详情', headerBarShow: true, activeMenu: '/businessPage/reimbursement' },
    hidden: true
  }
];

// 核算
const businessRouter = [
  {
    path: '/businessPage',
    component: Layout,
    redirect: '/businessPage/dayAccount',
    name: 'businessPage',
    meta: { title: '财务', icon: 'sidebar-business', authControl: pageAllAuth },
    children: [
      ...listRouter,
      ...inlineRouter
    ]
  }
];
export default businessRouter;
